package Movie;

use Moose;
use Readonly;
use feature qw(switch);

# has 'CHILDRENS' => (
#   is => 'ro',
#   isa => int,
#   default => 2,
# );

# has 'REGULAR' => (
#   is => 'ro',
#   isa => int,
#   default => 0,
# );

# has 'NEW_RELEASE' => (
#   is => 'ro',
#   isa => int,
#   default => 1,
# );

Readonly::Scalar our $CHILDREN => 2;
Readonly::Scalar our $REGULAR => 0;
Readonly::Scalar our $NEW_RELEASE => 1;

has '_title' => (
    isa => 'Str',
    is => 'ro',
    reader => 'get_title',
    required => 1,
);

has '_price_code' => (
    isa => 'Int',
    reader => 'get_price_code',
    writer => 'set_price_code',
    required => 1,
);

sub get_charge {
    my $self = shift;
    my $days_rented = shift;
    my $result = 0;
    given ($self->get_price_code()) {
        when(0) {
            $result = 2;
            if ($days_rented > 2) {
                $result += ($days_rented - 2) * 1;
            }
        }
        when(1) { $result = $days_rented * 3 }
        when(2) {
            $result = 1;
            if ($days_rented > 3) {
                $result += ($days_rented - 3) * 1;
            }
        }
    }
    return $result;
}

sub get_fre_rental_points {
    my $self = shift;
    my $days_rented = shift;
    my $fre_rental_points = 1;

    if ($self->get_price_code() == $Movie::NEW_RELEASE && $days_rented > 1) {
        $fre_rental_points++;
    }

    return $fre_rental_points;
}

1;